package edu.ciee.tz.action;

import java.util.List;

import javax.annotation.Resource;

import edu.ciee.tz.dao.TruckDAO;
import edu.ciee.tz.model.Laiyuan;
import edu.ciee.tz.model.Truck;

public class TruckAction {
	private String chepai;
	private String truck_type;
	private int size;
	private String gouru_time;
	private int laiyuan;
	
	private String tip;
	private List resultList;
	private TruckDAO truckDAO;
	
	public String getChepai() {
		return chepai;
	}
	public void setChepai(String chepai) {
		this.chepai = chepai;
	}
	public String getTruck_type() {
		return truck_type;
	}
	public void setTruck_type(String truck_type) {
		this.truck_type = truck_type;
	}
	public int getSize() {
		return size;
	}
	public void setSize(int size) {
		this.size = size;
	}
	public String getGouru_time() {
		return gouru_time;
	}
	public void setGouru_time(String gouru_time) {
		this.gouru_time = gouru_time;
	}
	public int getLaiyuan() {
		return laiyuan;
	}
	public void setLaiyuan(int laiyuan) {
		this.laiyuan = laiyuan;
	}
	public String getTip() {
		return tip;
	}
	public void setTip(String tip) {
		this.tip = tip;
	}
	public List getResultList() {
		return resultList;
	}
	public void setResultList(List resultList) {
		this.resultList = resultList;
	}
	public TruckDAO getTruckDAO() {
		return truckDAO;
	}
	@Resource
	public void setTruckDAO(TruckDAO truckDAO) {
		this.truckDAO = truckDAO;
	}
	public String forLuru() throws Exception {		
		return "success";		
	}
	public String insert(){
		try{
			Truck truck=new Truck();
			
			truck.setChepai(this.getChepai());
			truck.setGouru_time(this.getGouru_time());
			truck.setTruck_type(this.getTruck_type());
			truck.setSize(this.getSize());
			truck.setGouru_time(this.getGouru_time());
			
			Laiyuan ly=new Laiyuan();
			ly.setId(this.getLaiyuan());
			truck.setLaiyuan(ly);
			this.getTruckDAO().insert(truck);
			
			return "success";
		}catch(Exception e){
			this.setTip(e.toString());
			return "error";
		}
	}
	public String delete(){
		try{
			Truck truck=new Truck();
			
			truck.setChepai(this.getChepai());
			truck.setGouru_time(this.getGouru_time());
			truck.setTruck_type(this.getTruck_type());
			Laiyuan ly=new Laiyuan();
			ly.setId(this.getLaiyuan());
			truck.setLaiyuan(ly);
			
			truck.setSize(this.getSize());
			truck.setGouru_time(this.getGouru_time());
			
			this.getTruckDAO().delete(truck);
			
			return "refresh";
		}catch(Exception e){
			this.setTip(e.toString());
			e.printStackTrace();
			return "error";
		}
	}
	public String forEdit(){
		return "success";
	}
	public String edit(){
		try{
			Truck truck=new Truck();
			
			truck.setChepai(this.getChepai());
			truck.setGouru_time(this.getGouru_time());
			truck.setTruck_type(this.getTruck_type());
			Laiyuan ly=new Laiyuan();
			ly.setId(this.getLaiyuan());
			truck.setLaiyuan(ly);
			
			truck.setSize(this.getSize());
			truck.setGouru_time(this.getGouru_time());
			
			this.getTruckDAO().update(truck);
			
			return "refresh";
		}catch(Exception e){
			this.setTip(e.toString());
			e.printStackTrace();
			return "error";
		}
	}
	public String search(){
		try{
			Truck truck=new Truck();
			
			truck.setChepai(this.getChepai());
			truck.setGouru_time(this.getGouru_time());
			truck.setTruck_type(this.getTruck_type());
			Laiyuan ly=new Laiyuan();
			ly.setId(this.getLaiyuan());
			truck.setLaiyuan(ly);
			
			truck.setSize(this.getSize());
			truck.setGouru_time(this.getGouru_time());
			
			this.setResultList(this.getTruckDAO().search(truck));
			
			return "success";
		}catch(Exception e){
			this.setTip(e.toString());
			return "error";
		}
	}
}
